<template>
	<view class="number">
		<view class="sub" @tap.stop="sub(index)">
			<view class="icon cuIcon-move"></view>
		</view>
		<view class="input">
			<input type="number" v-model.number="input" />
		</view>
		<view class="add" @tap.stop="add(index)">
			<view class="icon cuIcon-add"></view>
		</view>
	</view>
</template>

<script>
	export default {
		props: {
			value: {
			  type: Number,
			  default: 1
			},
			index: {
				type: Number,
				default: 1
			}
		},
		data() {
			return {
				input: 1
			}
		},
		watch: {
		    value(value) {
		        this.input = value
		    },
		    input(value) {
		        this.$emit('input', value);
		    }
		},
		methods: {
			sub(index) {
				if(this.input <= 1) return
				this.input --;
				
			},
			add(index) {
				this.input ++;
			}
		}
	}
</script>

<style lang="scss">
	.number{
		display: flex;
		justify-content: center;
		align-items: flex-end;
		.input{
			width: 32upx;
			height: 32upx;
			margin: 0 10upx;
			input{
				width: 32upx;
				height: 32upx;
				display: flex;
				justify-content: center;
				align-items: center;
				text-align: center;
				font-size: 26upx;
			}
		}
		.sub ,.add{
			width: 32upx;
		    height: 32upx;
		    background-color: #f3f3f3;
		    border-radius: 50%;
			.icon{
				font-size: 22upx;
				width: 32upx;
				height: 32upx;
				display: flex;
				justify-content: center;
				align-items: center;
				
			}
		}
	}
</style>
